<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>会员资料编辑-WeAdmin Frame型后台管理系统-WeAdmin 1.0</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
		<link rel="stylesheet" href="../../static/css/font.css">
		<link rel="stylesheet" href="../../static/css/weadmin.css">
		<script src="https://libs.baidu.com/jquery/2.1.4/jquery.min.js"></script>
		<!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
		<!--[if lt IE 9]>
	      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
	      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
	    <![endif]-->
	</head>

	<body>
		<div class="weadmin-body">
			<form class="layui-form" lay-filter="test">
				<div class="layui-form-item">
					<label for="name" class="layui-form-label">
		               社团名
		            </label>
					<div class="layui-input-inline">
						<input type="text" id="name" name="name" lay-verify="required|nikename" autocomplete="off" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label for="nums" class="layui-form-label">
						人数
					</label>
					<div class="layui-input-inline">
						<input type="text" id="nums" name="nums" lay-verify="required" autocomplete="off" class="layui-input">
					</div>
				</div>

				<div class="layui-form-item">
					<label for="createDate" class="layui-form-label">
                        创建时间
              </label>
					<div class="layui-input-inline">
                    <input type="text" id="createDate" name="createDate" lay-verify="required" autocomplete="off" class="layui-input">
                </div>
				</div>

				<div class="layui-form-item">
					<label  class="layui-form-label">
						社团级别
					</label>
					<div class="layui-input-inline">
						<select id=“"level" name="level">
							<option>请选择分类</option>
							<option value="1">五星级</option>
							<option value="2">四星级</option>
							<option value="3">三星级</option>
						</select>
					</div>
				</div>
				<div class="layui-form-item">
					<label for="details" class="layui-form-label">
						简介
					</label>
					<div class="layui-input-inline">
						<input type="text" id="details" name="details" autocomplete="off" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label for="createDate" class="layui-form-label">
              </label>
					<button class="layui-btn" lay-filter="update" lay-submit="">确定</button>
                </div>
			</form>
		</div>
		<script src="../../lib/layui/layui.js" charset="utf-8"></script>
		<script type="text/javascript">
			layui.extend({
				admin: '{/}../../static/js/admin'
			});

			var dataId;
			var nums;
			function child(data){
			    dataId = data.id;
			    nums = data.nums;
			}

            layui.use(['form', 'jquery', 'admin','layer'], function() {
				var form = layui.form,
					$ = layui.jquery,
					admin = layui.admin,
					layer = layui.layer;
                var index = parent.layer.getFrameIndex(window.name);

                //自定义验证规则
                form.verify({
                    phone: [/^1[3|4|5|7|8]\d{9}$/, '手机必须11位，只能是数字！']
                });
				//页面初始化加载
				$(function(){
					setTimeout(function(){
						frameVal();
					},100);
				});  
				function frameVal(){
				    //layer.alert(dataId);
				    //获取URL中的请求参数
					var index = parent.layer.getFrameIndex(window.name);
					$.ajax({
                        type: "get",
                        url: "/api/organ/queryOrganListById?id="+dataId,
                        success: function(res){
                            //formTest 即 class="layui-form" 所在元素属性 lay-filter="" 对应的值
                            form.val("test", {
                                "name": res.name // "name": "value"
                                ,"createDate": res.createDate
                                ,"details": res.details
								,"nums":res.nums
								,"level":res.level
                            });
                            $("select[name='level']").val(res.level);
                            form.render('select');
                        }
                    });
				}
				//监听提交
				form.on('submit(update)', function(data) {
                    var f = data.field;
					console.log(data);
					var d =   {
                        "id":dataId,
                            "nums":f.nums,
                            "createDate":f.createDate,
                            "name":f.name,
                            "details":f.details,
							"level":f.level
                    };
                    $.ajax({
                        type: "post",
                        url: '/api/organ/updateOrgan',
                        contentType:'application/json;charset=UTF-8',
                        data:JSON.stringify(d),
                        success: function(res){
                            if(res.code ==0|| res.msg=="成功")
                                layer.alert("增加成功", {
                                    icon: 6
                                }, function() {
                                    // 获得frame索引
                                    var index = parent.layer.getFrameIndex(window.name);
                                    //关闭当前frame
                                    parent.layer.close(index);
                                });
                        }
                    });
					return false;
				});


			});
		</script>
	</body>

</html>